package shared.io.game;

import java.awt.Point;
import java.io.Serializable;

public class Room implements Serializable {
   
   private static final long serialVersionUID = 8686686914947092316L;
   private byte tile;
   /**
    * How lighted this room is <br>
    * 1 - bright <br>
    * 0 - dark
    */
   private float light;
   private int x;
   private int y;
   
   /**
    * @param x    x-position of the room
    * @param y    y-position of the room
    * @param tile    tile of the room (wall, floor..)
    * @param lightLevel   how much light does the room have
    */
   public Room(int x, int y, byte tile, float light) {
      this.x = x;
      this.y = y;
      this.tile = tile;
      this.light = light;
   }

   public byte getTile() {
      return tile;
   }

   public void setTile(byte tile) {
      this.tile = tile;
   }

   public float getLight() {
      return light;
   }

   public void setLight(float light) {
      if (light < 0) light = 0;
      this.light = light;
   }
   
   /**
    * Can only make the room lighter than already is
    * If parameter is lower than light level has no effect
    */
   public void increaseToLight(float light) {
      if (light <= this.light) return;
      setLight(light);
   }

   public int getX() {
      return x;
   }

   public void setX(int x) {
      this.x = x;
   }

   public int getY() {
      return y;
   }

   public void setY(int y) {
      this.y = y;
   }
   
   public Point getLoc() {
      return new Point(x, y);
   }

   @Override
   public boolean equals(Object obj) {
      if (this == obj)
         return true;
      if (obj == null)
         return false;
      if (!(obj instanceof Room))
         return false;
      Room other = (Room) obj;
      if (light != other.light) 
         return false;
      if (tile != other.tile)
         return false;
      if (x != other.x)
         return false;
      if (y != other.y)
         return false;
      return true;
   }  
}
